package cn.roadtrip.mtravelbusinessmodule.bs.travelline;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.crypto.digest.MD5;
import cn.roadtrip.mtravelbusinessmodule.bs.basic.BasicBusinessImpl;
import cn.roadtrip.mtravelbusinessmodule.bs.page.TravelPageWrapper;
import cn.roadtrip.mtravelbusinessmodule.bs.tuorgroup.TourTravelImpl;
import cn.roadtrip.mtravelbusinessmodule.bs.vpo.BSTravelPageWrapper_TravelGroupVPO;
import cn.roadtrip.mtravelbusinessmodule.sql.couple.travelgroup.dto.BsTravelGroupMainTuorTravelLineRecordDTO;
import cn.roadtrip.mtravelbusinessmodule.sql.couple.travelgroup.dto.BsTravelGroupTraveListGroupDTO;
import cn.roadtrip.mtravelbusinessmodule.sql.couple.travelgroup.tables.records.BsTravelgroupMaintourtravelrecordbindtravellistgroupRecord;
import cn.roadtrip.mtravelbusinessmodule.sql.couple.travelgroup.tables.records.BsTravelgroupMaintuortravellinerecordRecord;
import cn.roadtrip.mtravelbusinessmodule.sql.couple.travelgroup.tables.records.BsTravelgroupStartfromcityRecord;
import cn.roadtrip.mtravelbusinessmodule.sql.couple.travelgroup.tables.records.BsTravelgroupTravelistgroupRecord;
import cn.roadtrip.mtravelbusinessmodule.sql.couple.travelline.Tables;
import cn.roadtrip.mtravelbusinessmodule.sql.couple.travelline.dto.BsScenicDTO;
import cn.roadtrip.mtravelbusinessmodule.sql.couple.travelline.dto.BsTravelLinePlatPreTravelLineDTO;
import cn.roadtrip.mtravelbusinessmodule.sql.couple.travelline.tables.records.BsTravellinePlatpretravellineRecord;
import cn.roadtrip.mtravelbusinessmodule.sql.couple.travelline.vpo.VPO_PreTravelLineDetail;
import cn.roadtrip.mtravelbusinessmodule.sql.couple.travelline.vpo.VPO_PreTravelLineList;
import cn.roadtrip.mtravelbusinessmodule.sql.couple.travelline.vpo.VPO_ScenicGroupWithDetail;
import cn.roadtrip.utilmodule.util.DataBean;
import cn.roadtrip.utilmodule.util.enumpck.*;
import com.github.yitter.idgen.YitIdHelper;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import lombok.*;
import org.jooq.DSLContext;
import org.jooq.Record6;
import org.jooq.Result;
import org.jooq.impl.DSL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors;

import static cn.roadtrip.mtravelbusinessmodule.sql.couple.Tables.BS_USERLAYOUT_USERINFOR;
import static cn.roadtrip.mtravelbusinessmodule.sql.couple.tables.CoupleComment.COUPLE_COMMENT;
import static cn.roadtrip.mtravelbusinessmodule.sql.couple.travelgroup.Tables.*;
import static cn.roadtrip.mtravelbusinessmodule.sql.couple.travelline.Tables.BS_SCENIC;
import static cn.roadtrip.mtravelbusinessmodule.sql.couple.travelline.Tables.BS_TRAVELLINE_PRETRAVELLINESCENICGROUP;
import static cn.roadtrip.mtravelbusinessmodule.sql.couple.travelline.tables.BsTravellinePlatpretravelline.BS_TRAVELLINE_PLATPRETRAVELLINE;
import static cn.roadtrip.utilmodule.util.DataBean.err;
import static cn.roadtrip.utilmodule.util.DataBean.suc;

/**
 * 旅游路线操作
 */
@Component
public class TravelLineImpl {

    @Autowired
    private DSLContext dslContext;

    @Autowired
    private ScenicImpl scenicImpl;

    @Autowired
    private BasicBusinessImpl basicBusinessImpl;


    private ExecutorService queryService;

    @PostConstruct
    public void init() {
        queryService = Executors.newFixedThreadPool(12);
    }

    @PreDestroy
    public void destroy() {
        try {
            queryService.shutdown();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class Model_updatePreTravelLineInfor {
        private String preTravelLineId;
        private Enum_TravelLineType type;
        private Integer minDay;
        private Integer maxDay;
        private String preLineName;//预设路线名称
        private String contractId;//绑定合同ID
        private String insuranceId; //绑定保险ID
        private java.util.List<String> images;//图片数组
        private java.util.List<_StartPoint_> startPoint;//上车地点
        private java.util.Map<String, Object> extInfor;
    }

    /**
     * 更新旅游路线信息
     *
     * @param model
     * @return
     */
    public DataBean updatePreTravelLineInfor(Model_updatePreTravelLineInfor model) {
        try {
            //检查是否有重名

            try {
                model.setPreLineName(model.getPreLineName().trim());
                BsTravellinePlatpretravellineRecord r = dslContext.selectFrom(BS_TRAVELLINE_PLATPRETRAVELLINE)
                        .where(
                                BS_TRAVELLINE_PLATPRETRAVELLINE.TRASH.eq(false)
                                        .and(BS_TRAVELLINE_PLATPRETRAVELLINE.TYPE.eq(model.getType().getCode()))
                                        .and(BS_TRAVELLINE_PLATPRETRAVELLINE.PRELINENAME.eq(model.getPreLineName()))
                        ).fetchOne();
                if (r != null) {
                    return err("same-name", "路线名重复");
                }
            } catch (Exception e) {
                e.printStackTrace();
                return err("err", e.getMessage());
            }

            return dslContext.transactionResult(ctx -> {
                Gson gson = new Gson();
                int count = dslContext.update(BS_TRAVELLINE_PLATPRETRAVELLINE)
                        .set(BS_TRAVELLINE_PLATPRETRAVELLINE.TYPE, model.getType().getCode())
                        .set(BS_TRAVELLINE_PLATPRETRAVELLINE.MINDAY, model.getMinDay())
                        .set(BS_TRAVELLINE_PLATPRETRAVELLINE.MAXDAY, model.getMinDay())
                        .set(BS_TRAVELLINE_PLATPRETRAVELLINE.PRELINENAME, model.getPreLineName())
                        .set(BS_TRAVELLINE_PLATPRETRAVELLINE.CONTRACTID, model.getContractId())
                        .set(BS_TRAVELLINE_PLATPRETRAVELLINE.INSURANCEID, model.getInsuranceId())
                        .set(BS_TRAVELLINE_PLATPRETRAVELLINE.IMAGES, gson.toJson(model.getImages()))
                        .set(BS_TRAVELLINE_PLATPRETRAVELLINE.STARTPOINT, gson.toJson(model.getMinDay()))
                        .set(BS_TRAVELLINE_PLATPRETRAVELLINE.EXTINFOR, gson.toJson(model.getMinDay()))
                        .where(BS_TRAVELLINE_PLATPRETRAVELLINE.ID.eq(model.getPreTravelLineId()))
                        .execute();
                dslContext.commit();
                if (count == 0) {
                    return err("err", "更新失败");
                }
                return suc(true, 1, "suc", "操作成功");
            });
        } catch (Exception e) {
            e.printStackTrace();
            return err("trans-err", e.getMessage());
        }
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class Model_getTravelLineDetail {
        private String preTravelLineId;
    }

    /**
     * 查询出旅游路线详情
     *
     * @param model
     * @return
     */
    public DataBean getPreTravelLineDetail(Model_getTravelLineDetail model) {
        try {
            //查询路线
            BsTravelLinePlatPreTravelLineDTO line = dslContext.selectFrom(BS_TRAVELLINE_PLATPRETRAVELLINE)
                    .where(BS_TRAVELLINE_PLATPRETRAVELLINE.ID.eq(model.getPreTravelLineId()))
                    .fetchOne().into(BsTravelLinePlatPreTravelLineDTO.class);
            if (line == null) {
                return DataBean.errEmpty();
            }
            //查询景区分组
            DataBean<java.util.Map<Integer, java.util.List<VPO_ScenicGroupWithDetail>>> scenicGroupMapDB = scenicImpl._getScenicGroupByTravelLineId(model.getPreTravelLineId());
            if (scenicGroupMapDB.getTotalCount().intValue() == 0) {
                return scenicGroupMapDB;
            }
            Gson gson = new Gson();
            System.out.println("城市id");
            java.util.List<String> startCityIds = new ArrayList<>();
            try {
                startCityIds = Arrays.asList(line.getCityIds().split(","));
                System.out.println(Arrays.toString(line.getCityIds().split(",")));
            } catch (Exception e) {
                e.printStackTrace();
            }
            java.util.List<TourTravelImpl._CityCode_> citys = new java.util.ArrayList<TourTravelImpl._CityCode_>();
            if (!startCityIds.isEmpty()) {
                //查询出发城市
                try {
                    citys = dslContext.select(
                            DSL.field("city_id").as("cityId"),
                            DSL.field("name").as("cityName"),
                            DSL.field("cityCode").as("cityCode")
                    ).from(
                            "sys_category"
                    ).where(
                            DSL.field("city_id").in(startCityIds)
                    ).fetchInto(TourTravelImpl._CityCode_.class);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            VPO_PreTravelLineDetail data = new VPO_PreTravelLineDetail(
                    line.getId(),
                    line.getTrash(),
                    line.getOpened(),
                    line.getType(),
                    line.getTenantId(),
                    line.getMinDay(),
                    line.getMaxDay(),
                    line.getPreLineName(),
                    line.getContractId(),
                    line.getInsuranceId(),
                    gson.fromJson(line.getStartPoint(), new com.google.gson.reflect.TypeToken<java.util.List<VPO_PreTravelLineDetail.StartPoint>>() {
                    }.getType()),
                    gson.fromJson(line.getImages(), new com.google.gson.reflect.TypeToken<java.util.List<String>>() {
                    }.getType()),
                    gson.fromJson(line.getExtInfor(), new com.google.gson.reflect.TypeToken<java.util.Map<String, Object>>() {
                    }.getType()),
                    scenicGroupMapDB.getResult(),
                    citys
            );


            return suc(data, 1, "suc", "操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return err("err", e.getMessage());
        }
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class Model_getTravelLineList {
        private String cityName;
        private Boolean opened;//是否开放
        private Enum_TravelLineType type;
        private Integer playDays;//游玩天数
        private Integer cpage;
        private Integer pagesize;
    }

    /**
     * 查询旅游路线
     *
     * @param model
     * @return
     */
    public DataBean getTravelLineList(Model_getTravelLineList model) {
        DataBean<String> tenantDB = basicBusinessImpl._getTenantIdByCityName(model.getCityName());
        if (tenantDB.getTotalCount().intValue() == 0)
            return tenantDB;
        if (model.getOpened() == null) {
            model.setOpened(true);
        }
        int count = dslContext.selectCount().from(
                BS_TRAVELLINE_PLATPRETRAVELLINE
        ).where(
                BS_TRAVELLINE_PLATPRETRAVELLINE.TRASH.eq(false)
                        .and(model.getOpened() == null ? DSL.noCondition() : BS_TRAVELLINE_PLATPRETRAVELLINE.OPENED.eq(model.getOpened()))
                        .and(model.getType() == null ? DSL.noCondition() : BS_TRAVELLINE_PLATPRETRAVELLINE.TYPE.eq(model.getType().getCode()))
                        .and(BS_TRAVELLINE_PLATPRETRAVELLINE.TENANTID.eq(tenantDB.getResult()))
                        .and(
                                model.getPlayDays() == null ? DSL.noCondition() :
                                        (
                                                BS_TRAVELLINE_PLATPRETRAVELLINE.MINDAY.lessOrEqual(model.getPlayDays())
                                                        .and(BS_TRAVELLINE_PLATPRETRAVELLINE.MAXDAY.greaterOrEqual(model.getPlayDays()))
                                        )
                        )
        ).fetchOne().value1();
        if (count == 0)
            return DataBean.sucEmpty();
        //查询出旅游路线列表
        java.util.List<BsTravelLinePlatPreTravelLineDTO> list = dslContext.select(
                        BS_TRAVELLINE_PLATPRETRAVELLINE.ID,
                        BS_TRAVELLINE_PLATPRETRAVELLINE.TRASH,
                        BS_TRAVELLINE_PLATPRETRAVELLINE.OPENED,
                        BS_TRAVELLINE_PLATPRETRAVELLINE.TYPE,
                        BS_TRAVELLINE_PLATPRETRAVELLINE.TENANTID,
                        BS_TRAVELLINE_PLATPRETRAVELLINE.MINDAY,
                        BS_TRAVELLINE_PLATPRETRAVELLINE.MAXDAY,
                        BS_TRAVELLINE_PLATPRETRAVELLINE.PRELINENAME,
                        BS_TRAVELLINE_PLATPRETRAVELLINE.STARTPOINT,
                        BS_TRAVELLINE_PLATPRETRAVELLINE.IMAGES
                )
                .from(BS_TRAVELLINE_PLATPRETRAVELLINE)
                .where(
                        BS_TRAVELLINE_PLATPRETRAVELLINE.TRASH.eq(false)
                                .and(model.getOpened() == null ? DSL.noCondition() : BS_TRAVELLINE_PLATPRETRAVELLINE.OPENED.eq(model.getOpened()))
                                .and(model.getType() == null ? DSL.noCondition() : BS_TRAVELLINE_PLATPRETRAVELLINE.TYPE.eq(model.getType().getCode()))
                                .and(BS_TRAVELLINE_PLATPRETRAVELLINE.TENANTID.eq(tenantDB.getResult()))
                                .and(
                                        model.getPlayDays() == null ? DSL.noCondition() :
                                                (
                                                        BS_TRAVELLINE_PLATPRETRAVELLINE.MINDAY.lessOrEqual(model.getPlayDays())
                                                                .and(BS_TRAVELLINE_PLATPRETRAVELLINE.MAXDAY.greaterOrEqual(model.getPlayDays()))
                                                )
                                )
                )
                .orderBy(BS_TRAVELLINE_PLATPRETRAVELLINE.ID.desc())
                .limit(model.getCpage() * model.getPagesize(), model.getPagesize())
                .fetch().into(BsTravelLinePlatPreTravelLineDTO.class);
        java.util.List<VPO_PreTravelLineList> rslist = new ArrayList<>();
        Gson gson = new Gson();
        for (BsTravelLinePlatPreTravelLineDTO m : list) {
            rslist.add(new VPO_PreTravelLineList(
                    m.getId(),
                    m.getTrash(),
                    m.getOpened(),
                    m.getType(),
                    m.getTenantId(),
                    m.getMinDay(),
                    m.getMaxDay(),
                    m.getPreLineName(),
                    gson.fromJson(m.getStartPoint(), new com.google.gson.reflect.TypeToken<java.util.List<VPO_PreTravelLineList.StartPoint>>() {
                    }.getType()),
                    gson.fromJson(m.getImages(), new com.google.gson.reflect.TypeToken<java.util.List<String>>() {
                    }.getType())
            ));
        }
        list.clear();
        return suc(rslist, count, "suc", "操作成功");
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class Model_turnOffTravelLine {
        private String preTravelLineId;
    }

    /**
     * 关闭路线
     *
     * @param model
     * @return
     */
    public DataBean turnOffTravelLine(Model_turnOffTravelLine model) {
        try {
            return dslContext.transactionResult(ctx -> {
                int count = dslContext.update(BS_TRAVELLINE_PLATPRETRAVELLINE)
                        .set(BS_TRAVELLINE_PLATPRETRAVELLINE.OPENED, false)
                        .where(BS_TRAVELLINE_PLATPRETRAVELLINE.ID.eq(model.getPreTravelLineId())
                        ).execute();
                dslContext.commit();
                if (count == 0)
                    return err("fail", "操作失败");
                return suc(true, 1, "suc", "操作成功");
            });
        } catch (Exception e) {
            e.printStackTrace();
            return err("trans-err", e.getMessage());
        }
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class Model_turnOnTravelLine {
        private String preTravelLineId;
    }

    /**
     * 开启路线
     *
     * @param model
     * @return
     */
    public DataBean turnOnTravelLine(Model_turnOnTravelLine model) {
        try {
            return dslContext.transactionResult(ctx -> {
                int count = dslContext.update(BS_TRAVELLINE_PLATPRETRAVELLINE)
                        .set(BS_TRAVELLINE_PLATPRETRAVELLINE.OPENED, true)
                        .where(BS_TRAVELLINE_PLATPRETRAVELLINE.ID.eq(model.getPreTravelLineId())
                        ).execute();
                dslContext.commit();
                if (count == 0)
                    return err("fail", "操作失败");
                return suc(true, 1, "suc", "操作成功");
            });
        } catch (Exception e) {
            e.printStackTrace();
            return err("trans-err", e.getMessage());
        }
    }


    /**
     * 旅游路线绑定景区
     *
     * @param models
     * @return
     */
    public DataBean bindScenicGroup(java.util.List<ScenicImpl.Model_setScenicGroup> models) {
        //查询路线是否存在

        try {
            int count = dslContext.selectCount().from(BS_TRAVELLINE_PLATPRETRAVELLINE)
                    .where(BS_TRAVELLINE_PLATPRETRAVELLINE.TRASH.eq(false)
                            .and(BS_TRAVELLINE_PLATPRETRAVELLINE.ID.eq(models.get(0).getTravelLineId()))
                    ).fetchOne().value1();
            if (count == 0) {
                return err("travel-line-not-exist", "路线不存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return err("fail", e.getMessage());
        }

        return scenicImpl.setScenicGroup(models);

    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class Model_trashPreTravelLine {
        private String preTravelLineId;
    }

    /**
     * 删除预置行程
     *
     * @param model
     * @return
     */
    public DataBean trashPreTravelLine(Model_trashPreTravelLine model) {
        try {
            return dslContext.transactionResult(ctx -> {
                int count = dslContext.update(BS_TRAVELLINE_PLATPRETRAVELLINE)
                        .set(BS_TRAVELLINE_PLATPRETRAVELLINE.TRASH, true)
                        .where(BS_TRAVELLINE_PLATPRETRAVELLINE.ID.eq(model.getPreTravelLineId())
                        ).execute();
                dslContext.commit();
                if (count == 0)
                    return err("fail", "操作失败");
                return suc(true, 1, "suc", "操作成功");
            });
        } catch (Exception e) {
            e.printStackTrace();
            return err("trans-err", e.getMessage());
        }
    }


    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class _StartPoint_Address_ {
        private String pickUpId;//上车地点ID
        private String gis;//地理坐标
        private String point;//地点
        private Integer maxNum;//最大人数
    }

    /**
     * 上车地点
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class _StartPoint_ {
        private String mainCity;//城市名
        private java.util.List<_StartPoint_Address_> address;//街道点
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class Model_createTravelLine {
        private String tenantId;
        private Enum_TravelLineType type;
        private Integer minDay;
        private Integer maxDay;
        private String preLineName;//预设路线名称
        private String contractId;//绑定合同ID
        private String insuranceId; //绑定保险ID
        private java.util.List<String> images;//图片数组
        //        private java.util.List<_StartPoint_> startPoint;//上车地点
        private String startPoint;//上车地点
        private java.util.Map<String, Object> extInfor;
    }

    /**
     * 创建旅游路线
     *
     * @return
     */
    public DataBean createTravelLine(
            Model_createTravelLine model
    ) {
        //从旅游名字，先看有没有重复得
        try {
            model.setPreLineName(model.getPreLineName().trim());
            BsTravellinePlatpretravellineRecord r = dslContext.selectFrom(BS_TRAVELLINE_PLATPRETRAVELLINE)
                    .where(
                            BS_TRAVELLINE_PLATPRETRAVELLINE.TRASH.eq(false)
                                    .and(BS_TRAVELLINE_PLATPRETRAVELLINE.TYPE.eq(model.getType().getCode()))
                                    .and(BS_TRAVELLINE_PLATPRETRAVELLINE.PRELINENAME.eq(model.getPreLineName()))
                    ).fetchOne();
            if (r != null) {
                return err("same-name", "该路线已存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return err("err", e.getMessage());
        }

        //保存路线
        try {
            return dslContext.transactionResult(ctx -> {
                Gson gson = new Gson();
                int cout = dslContext.insertInto(BS_TRAVELLINE_PLATPRETRAVELLINE)
                        .set(
                                new BsTravellinePlatpretravellineRecord(
                                        "" + YitIdHelper.nextId(),
                                        false,
                                        false,
                                        model.getType().getCode(),
                                        model.getTenantId(),
                                        model.getMinDay(),
                                        model.getMaxDay(),
                                        model.getPreLineName(),
                                        model.getContractId(),
                                        model.getInsuranceId()
                                        , "{}"
                                        , "{}"
//                                        gson.toJson(model.getStartPoint()),
                                        , model.getStartPoint(),
                                        gson.toJson(model.getImages()),
                                        gson.toJson(model.getExtInfor())
                                )
                        ).execute();
                dslContext.commit();
                if (cout == 0)
                    return err("trans-err", "操作失败");
                return suc(true, 1, "suc", "操作成功");
            });
        } catch (Exception e) {
            e.printStackTrace();
            return err("trans-err", e.getMessage());
        }

    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class _TitleGroup_ {
        private String mainTitle;//主标题
        private String secondTitle;//副标题
    }

    //出行日历
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class _TravelCalendar_ {
        /**
         * {
         * "markDate":"2024-02-14",
         * "week":"周一",
         * "startPrice":"1000"
         * }
         */
        private String markDate;
        private String week;
        private String startPrice;
        private Integer minNum;//最小出发人数
    }


    /**
     * 阶梯价格
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class _StepPrice_ {
        private Integer minNum;//最小人数
        private String price;//价格
        private Integer maxNum;//最大人数
    }

    /**
     * 每日行程
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class _TravelLine_DayScenic_ {
        private String scenicId;//景点ID
        private Integer sortOrder;//排序
        private Integer dayNum;//第几天
        private String scenicTitle;
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class Model_createTravelLineGroup {

        private java.util.List<String> startFromCityIds;//出发城市ID

        private String startDate;//大团发车开始日期
        private String endDate;//大团发车结束日期
        private String mainStartPrice;//大团发车起步价格
        //        private java.util.List<_StartPoint_> startPoint;
        private Object startPoint;
        private _TitleGroup_ titleGroup;//标题组
        private java.util.List<String> images;
        private java.util.List<_TravelCalendar_> travelCalendars;
        private java.util.Map<String, Object> content;//内容页
        private java.util.List<_StepPrice_> stepPrices;//阶梯价格
        private java.util.Map<String, Object> extInfor;//内容页
        private java.util.List<TourTravelImpl._TravelLine_DayScenic_> dayScenicList;//每日景点

        private Integer travelDays;
        private Integer maxUserNum;
        private String preTravelLineId;//预设路线
        private String tenantId;//租户ID

        //新增部分
        private Integer globMinNum;//全局最小出发人数
    }

    /**
     * 创建大团
     *
     * @param model
     * @return
     */
    public DataBean createTravelLineGroup(Model_createTravelLineGroup model) {
        try {
            return dslContext.transactionResult(ctx -> {
                //先循环创建小团
                java.util.List<String> tourTravelLineRecordIds = new ArrayList<>();
                Long currentTime = System.currentTimeMillis();
                Gson gson = new Gson();
                Long startDate = DateUtil.parseDate(model.getStartDate()).getTime();
                Long endDate = DateUtil.parseDate(model.getEndDate()).getTime();

                //用开始日期和结束日期创建日历
                if (model.getTravelCalendars() == null || model.getTravelCalendars().isEmpty()) {
                    java.util.List<_TravelCalendar_> travelCalendars = new ArrayList<>();
                    for (Long markDate = startDate; markDate <= endDate; markDate = markDate + DateUnit.DAY.getMillis()) {
                        Date md = new Date(markDate);
                        travelCalendars.add(new _TravelCalendar_(
                                DateUtil.formatDate(md),
                                switch (DateUtil.dayOfWeek(md)) {
                                    case 2:
                                        yield "周一";
                                    case 3:
                                        yield "周二";
                                    case 4:
                                        yield "周三";
                                    case 5:
                                        yield "周四";
                                    case 6:
                                        yield "周五";
                                    case 7:
                                        yield "周六";
                                    case 1:
                                        yield "周日";
                                    default:
                                        yield "异常";
                                },
                                model.getMainStartPrice(),
                                model.getGlobMinNum()

                        ));
                    }
                    model.setTravelCalendars(travelCalendars);
                }


//                for (Long markDate = startDate; markDate <= endDate; markDate = markDate + DateUnit.DAY.getMillis()) {
                for (_TravelCalendar_ tcal : model.getTravelCalendars()) {
                    Long markDate = DateUtil.parseDate(tcal.getMarkDate()).getTime();
//
//                }
//                for (_TravelCalendar_ tc : model.getTravelCalendars()) {
                    String tourTravelLineRecordId = YitIdHelper.nextId() + "";
                    tourTravelLineRecordIds.add(tourTravelLineRecordId);
                    int cout = dslContext.insertInto(BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD)
                            .set(
                                    new BsTravelgroupMaintuortravellinerecordRecord(
                                            tourTravelLineRecordId,
                                            Enum_TourTravelGroupType.Group.getCode(),
                                            Enum_MainTourTravelLineStats.Wait.getCode(),
                                            Enum_MainTourTravelLineDispatchStats.Audit.getCode(),
                                            "0",
                                            model.getPreTravelLineId(),
                                            model.getTenantId(),
                                            markDate,
                                            model.getTravelDays(),
                                            model.getMaxUserNum(),
                                            "0",
                                            "",
                                            "0",
                                            "0",
                                            "0",
                                            markDate - DateUnit.HOUR.getMillis() * 12,
                                            currentTime,
                                            "",
                                            model.getTitleGroup().getMainTitle(),
                                            "",
                                            gson.toJson(model.getExtInfor()),
                                            "[]",
                                            gson.toJson(model.getDayScenicList())
                                    )
                            )
                            .execute();
                    if (cout == 0)
                        throw new RuntimeException("操作失败，【" + DateUtil.format(new Date(markDate), "yyyy-MM-dd") + "】");
                    //新增出发城市
                    for (String cityId : model.getStartFromCityIds()) {
                        dslContext.insertInto(BS_TRAVELGROUP_STARTFROMCITY)
                                .set(
                                        new BsTravelgroupStartfromcityRecord(
                                                YitIdHelper.nextId() + "",
                                                false,
                                                tourTravelLineRecordId,
                                                cityId,
                                                ""
                                        )
                                )
                                .execute();

                    }
                }
                // 再创建大团组
                String groupId = YitIdHelper.nextId() + "";

                {
                    int count = dslContext.insertInto(
                            BS_TRAVELGROUP_TRAVELISTGROUP
                    ).set(
                            new BsTravelgroupTravelistgroupRecord(
                                    groupId,
                                    false,
                                    Enum_TravelListGroupStats.Normal.getCode(),
                                    DateUtil.parseDate(model.getStartDate()).getTime(),
                                    DateUtil.parseDate(model.getEndDate()).getTime(),
                                    new BigDecimal(model.getMainStartPrice()),
                                    System.currentTimeMillis(),
//                                    gson.toJson(model.getStartPoint()),
                                    gson.toJson(model.getStartPoint()),
                                    gson.toJson(model.getTitleGroup()),
                                    gson.toJson(model.getImages()),
                                    model.getTravelCalendars() == null ? "[]" : gson.toJson(model.getTravelCalendars()),
                                    gson.toJson(tourTravelLineRecordIds),
                                    gson.toJson(model.getContent()),
                                    gson.toJson(model.getStepPrices()),
                                    gson.toJson(model.getExtInfor())

                            )
                    ).execute();
                    if (count == 0)
                        throw new RuntimeException("创建大团异常");
                }
                //再添加关联绑定
                {
                    for (String id : tourTravelLineRecordIds) {
                        int count = dslContext.insertInto(
                                BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP
                        ).set(
                                new BsTravelgroupMaintourtravelrecordbindtravellistgroupRecord(
                                        YitIdHelper.nextId() + "",
                                        groupId,
                                        id
                                )
                        ).execute();
                        if (count == 0)
                            throw new RuntimeException("创建大团异常");
                    }
                }
                dslContext.commit();
                return suc(true, 1, "suc", "操作成功");
            });
        } catch (Exception e) {
            e.printStackTrace();
            return err("trans-err", e.getMessage());
        }

    }


    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class Model_queryTravelLineGroupList {
        private String scenicId;//景点ID
        private String startDate;//发车时间
        private Integer cpage;
        private Integer pagesize;
    }

    /**
     * 查询大团列表
     *
     * @param model
     * @return
     */
    public DataBean queryTravelLineGroupList(Model_queryTravelLineGroupList model) {

        int count = 0;
        try {
            count = dslContext.selectCount(
                    )
                    .from(DSL.selectDistinct(
                                    BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.TRAVELLISTGROUPID
                            )
                            .from(BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP)
                            .where(
                                    BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.MAINTOURTRAVELRECORDID.in(
                                            DSL.select(
                                                            BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.ID
                                                    ).from(BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD)
                                                    .where(
                                                            BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.TYPE.eq(Enum_TourTravelGroupType.Group.getCode())
                                                    )
                                                    .and(BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.STATS.eq(
                                                            Enum_MainTourTravelLineStats.Wait.getCode()
                                                    ))
                                                    .and(
                                                            model.getStartDate() != null ?
                                                                    BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.STARTDATE.eq(DateUtil.parse(model.getStartDate()).getTime())
                                                                    : DSL.noCondition()
                                                    )
                                                    .and(BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.PRETRAVELLINEID.in(
                                                            DSL.select(Tables.BS_TRAVELLINE_PLATPRETRAVELLINE.ID)
                                                                    .from(Tables.BS_TRAVELLINE_PLATPRETRAVELLINE)
                                                                    .where(
                                                                            Tables.BS_TRAVELLINE_PLATPRETRAVELLINE.TRASH.eq(false)
                                                                    )
                                                                    .and(Tables.BS_TRAVELLINE_PLATPRETRAVELLINE.OPENED.eq(true))
                                                                    .and(
                                                                            model.getScenicId() != null ?
                                                                                    Tables.BS_TRAVELLINE_PLATPRETRAVELLINE.ID.in(
                                                                                            DSL.select(BS_TRAVELLINE_PRETRAVELLINESCENICGROUP.TRAVELLINEID)
                                                                                                    .from(BS_TRAVELLINE_PRETRAVELLINESCENICGROUP)
                                                                                                    .where(
                                                                                                            BS_TRAVELLINE_PRETRAVELLINESCENICGROUP.TRASH.eq(false)
                                                                                                    )
                                                                                                    .and(BS_TRAVELLINE_PRETRAVELLINESCENICGROUP.SCENICID.eq(model.getScenicId()))
                                                                                    )
                                                                                    : DSL.noCondition()
                                                                    )
                                                    ))
                                    )
                            ))
                    .fetchOne().value1();
            if (count == 0) {
                return DataBean.sucEmpty();
            }
        } catch (Exception e) {
            e.printStackTrace();
            return err("trans-err", e.getMessage());
        }

        java.util.List<String> travelListGroupList = new ArrayList<>();//大团ID
        try {
            java.util.List<String> ids = dslContext.selectDistinct(
                            BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.TRAVELLISTGROUPID
                    )
                    .from(BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP)
                    .where(
                            BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.MAINTOURTRAVELRECORDID.in(
                                    DSL.select(
                                                    BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.ID
                                            ).from(BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD)
                                            .where(
                                                    BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.TYPE.eq(Enum_TourTravelGroupType.Group.getCode())
                                            )
                                            .and(BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.STATS.eq(
                                                    Enum_MainTourTravelLineStats.Wait.getCode()
                                            ))
                                            .and(
                                                    model.getStartDate() != null ?
                                                            BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.STARTDATE.eq(DateUtil.parse(model.getStartDate()).getTime())
                                                            : DSL.noCondition()
                                            )
                                            .and(BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.PRETRAVELLINEID.in(
                                                    DSL.select(Tables.BS_TRAVELLINE_PLATPRETRAVELLINE.ID)
                                                            .from(Tables.BS_TRAVELLINE_PLATPRETRAVELLINE)
                                                            .where(
                                                                    Tables.BS_TRAVELLINE_PLATPRETRAVELLINE.TRASH.eq(false)
                                                            )
                                                            .and(Tables.BS_TRAVELLINE_PLATPRETRAVELLINE.OPENED.eq(true))
                                                            .and(
                                                                    model.getScenicId() != null ?
                                                                            Tables.BS_TRAVELLINE_PLATPRETRAVELLINE.ID.in(
                                                                                    DSL.select(BS_TRAVELLINE_PRETRAVELLINESCENICGROUP.TRAVELLINEID)
                                                                                            .from(BS_TRAVELLINE_PRETRAVELLINESCENICGROUP)
                                                                                            .where(
                                                                                                    BS_TRAVELLINE_PRETRAVELLINESCENICGROUP.TRASH.eq(false)
                                                                                            )
                                                                                            .and(BS_TRAVELLINE_PRETRAVELLINESCENICGROUP.SCENICID.eq(model.getScenicId()))
                                                                            )
                                                                            : DSL.noCondition()
                                                            )
                                            ))
                            )
                    )
                    .orderBy(BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.TRAVELLISTGROUPID.desc())
                    .limit(model.getCpage() * model.getPagesize(), model.getPagesize())
                    .fetchInto(String.class);
            travelListGroupList.addAll(ids);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        }
        java.util.Map<String, Integer> groupListNumMap = new HashMap<>();//大团报名人数
        java.util.List<BSTravelPageWrapper_TravelGroupVPO> rslist2 = new ArrayList<>();// 大团列表

        try {
            //查询大团人数
//            java.util.List<TravelPageWrapper._Count_Map_> idNums = dslContext.select(
//                           DSL.ifnull( DSL.count(BS_TRAVELGROUP_TOURORDERRECORD.ID),0).as("n"),
//                            BS_TRAVELGROUP_TOURORDERRECORD.TRAVELGROUPID.as("id")
//                    )
//                    .from(
//                            BS_TRAVELGROUP_TOURORDERRECORD
//                    ).where(
//                            BS_TRAVELGROUP_TOURORDERRECORD.STATS.in(
//                                    Enum_TravelGroupTourOrderStats.Join.getCode(),
//                                    Enum_TravelGroupTourOrderStats.Mark.getCode(),
//                                    Enum_TravelGroupTourOrderStats.Waitpay.getCode(),
//                                    Enum_TravelGroupTourOrderStats.Payed.getCode()
//                            )
//                    ).and(
//                            BS_TRAVELGROUP_TOURORDERRECORD.TRAVELGROUPID.in(
//                                    DSL.select(
//                                                    BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.MAINTOURTRAVELRECORDID
//                                            ).from(
//                                                    BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP,
//                                                    BS_TRAVELGROUP_TRAVELISTGROUP
//                                            ).where(
//                                                    BS_TRAVELGROUP_TRAVELISTGROUP.ID.in(travelListGroupList)
//                                            )
//                                            .and(
//                                                    BS_TRAVELGROUP_TRAVELISTGROUP.ID.eq(
//                                                            BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.TRAVELLISTGROUPID
//                                                    )
//                                            )
//                            )
//                    ).groupBy(
//                            BS_TRAVELGROUP_TOURORDERRECORD.TRAVELGROUPID
//                    ).fetchInto(TravelPageWrapper._Count_Map_.class);

            java.util.List<TravelPageWrapper._Count_Map_> idNums = dslContext.select(
                            DSL.count(DSL.field("rid")).as("n"),
                            DSL.field("t.id")
                    )
                    .from(
                            DSL.selectDistinct(
                                            BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.TRAVELLISTGROUPID.as("id"),
                                            BS_TRAVELGROUP_TOURORDERRECORD.ID.as("rid")
                                    ).from(
                                            BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP,
                                            BS_TRAVELGROUP_TOURORDERRECORD
                                    )
                                    .where(
                                            BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.TRAVELLISTGROUPID.in(travelListGroupList)
                                    )
                                    .and(
                                            BS_TRAVELGROUP_TOURORDERRECORD.STATS.in(
                                                    Enum_TravelGroupTourOrderStats.Join.getCode(),
                                                    Enum_TravelGroupTourOrderStats.Mark.getCode(),
                                                    Enum_TravelGroupTourOrderStats.Waitpay.getCode(),
                                                    Enum_TravelGroupTourOrderStats.Payed.getCode()
                                            )
                                    )
                                    .and(
                                            BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.MAINTOURTRAVELRECORDID.eq(
                                                    BS_TRAVELGROUP_TOURORDERRECORD.TRAVELGROUPID
                                            )
                                    ).asTable("t")
                    )
                    .groupBy(DSL.field("t.id"))
                    .fetchInto(TravelPageWrapper._Count_Map_.class);

            if (idNums == null || idNums.isEmpty()) {
//                return;
            }
            idNums.forEach(o -> {
                groupListNumMap.put(o.getId(), o.getN());
            });

            //查询大团信息
            java.util.List<TravelPageWrapper._TravelGroupVPO_> list = dslContext.selectDistinct(
                            BS_TRAVELGROUP_TRAVELISTGROUP.ID,
                            BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.TRAVELDAYS,
                            BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.PRETRAVELLINEID,
                            BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.TRAVELTITLE,
                            BS_TRAVELGROUP_TRAVELISTGROUP.STARTDATE,
                            BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.MAXUSERNUM,
                            BS_TRAVELGROUP_TRAVELISTGROUP.EXTINFOR,
                            Tables.BS_TRAVELLINE_PLATPRETRAVELLINE.IMAGES,
                            DSL.field(" 0 ").as("peopleNum"),
                            BS_TRAVELGROUP_STARTFROMCITY.CITYNAME.as("startFromCity"),
                            BS_TRAVELGROUP_STARTFROMCITY.CITYID.as("startFromCityId")
                    ).from(
                            DSL.select(
                                            BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.MAINTOURTRAVELRECORDID,
                                            BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.TRAVELLISTGROUPID.as("travelListGroupID")
                                    ).from(BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP)
                                    .where(
                                            BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.TRAVELLISTGROUPID.in(travelListGroupList)
                                    ).asTable("t")
                    ).leftJoin(BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD)
                    .on(BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.ID.eq(DSL.field("t.mainTourTravelRecordId", String.class)))
                    .leftJoin(
                            Tables.BS_TRAVELLINE_PLATPRETRAVELLINE
                    ).on(Tables.BS_TRAVELLINE_PLATPRETRAVELLINE.ID.eq(BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.PRETRAVELLINEID))
                    .leftJoin(BS_TRAVELGROUP_TRAVELISTGROUP)
                    .on(BS_TRAVELGROUP_TRAVELISTGROUP.ID.eq(DSL.field("t.travelListGroupID", String.class)))
                    .leftJoin(BS_TRAVELGROUP_STARTFROMCITY)
                    .on(BS_TRAVELGROUP_STARTFROMCITY.TRAVELGROUPID.eq(BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.ID))
                    .orderBy(BS_TRAVELGROUP_TRAVELISTGROUP.STARTDATE.desc())
                    .fetchInto(TravelPageWrapper._TravelGroupVPO_.class);

            Gson gson = new Gson();
            list.forEach(o -> {
                BSTravelPageWrapper_TravelGroupVPO vpo = new BSTravelPageWrapper_TravelGroupVPO();
                vpo.setId(o.getId());
                vpo.setTravelDays(o.getTravelDays());
                vpo.setPreTravelLineId(o.getPreTravelLineId());
                vpo.setTravelTitle(o.getTravelTitle());
                vpo.setStartDate(o.getStartDate());
                vpo.setMaxUserNum(o.getMaxUserNum());
                vpo.setExtInfor(gson.fromJson(o.getExtInfor(), java.util.Map.class));
                vpo.setImages(gson.fromJson(o.getImages(), java.util.List.class));
                vpo.setPeopleNum(groupListNumMap.get(o.getId()));
                rslist2.add(vpo);
            });
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        }

        return suc(rslist2, count, "suc", "操作成功");
    }


    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class Model_getHomePageTravelGroupListByKey {
        private java.util.List<String> keys;
        private Integer cpage;
        private Integer pagesize;
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class VPO_getHomePageTravelGroupListByKey {
        private String id;
        private Long startDate;
        private String travelTitle;
        private java.util.List<String> images;
        private java.util.Map<String, Object> extInfor;
        private Integer peopleNum;
        private java.util.List<String> userHeadCovers;//头像
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class _COUNT_getHomePageTravelGroupListByKey {
        private String travelGroupId;
        private Integer n;
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class _HEADCOVER_getHomePageTravelGroupListByKey {
        private String travelGroupId;
        private String headCover;
    }

    /**
     * 首页获取推荐团列表
     *
     * @return
     */
    public DataBean getHomePageTravelGroupListByKey(Model_getHomePageTravelGroupListByKey model) {
        try {
            return dslContext.transactionResult(ctx -> {

                int count = 0;
                {
                    //统计总条数
                    count = dslContext.select(
                            DSL.count(BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.ID)
                    ).from(
                            BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD
                    ).where(
                            BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.TYPE.eq(Enum_TourTravelGroupType.Self.getCode())
                    ).and(
                            BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.STATS.eq(Enum_MainTourTravelLineStats.Wait.getCode())
                    ).and(
                            BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.EXPIREDATE.ge(System.currentTimeMillis())
                    ).and(
                            BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.ID.in(
                                    DSL.selectDistinct(BS_TRAVELGROUP_BINDKEY.TRAVELGROUPID)
                                            .from(BS_TRAVELGROUP_BINDKEY)
                                            .where(BS_TRAVELGROUP_BINDKEY.STATS.eq(Enum_TravelGroupBindKeyStats.Top.getCode()))
                                            .and((model.getKeys() == null || model.getKeys().isEmpty()) ? DSL.noCondition() : BS_TRAVELGROUP_BINDKEY.KEYCODE.in(model.getKeys()))
                            )
                    ).fetchOne().value1();
                }
                if (count == 0) {
                    return DataBean.sucEmpty();
                }

                java.util.List<String> ids = new ArrayList<>();
                java.util.List<VPO_getHomePageTravelGroupListByKey> rslist = new ArrayList<>();
                {
                    //查询列表
                    /**
                     * 	BS_TravelGroup_MainTuorTravelLineRecord.id,
                     * 	BS_TravelGroup_MainTuorTravelLineRecord.startDate ,
                     * 	BS_TravelGroup_MainTuorTravelLineRecord.travelTitle,
                     * 	BS_TravelLine_PlatPreTravelLine.images,
                     * 	0 as peopleNum,
                     * 	BS_TravelGroup_MainTuorTravelLineRecord.extInfor
                     */

                    Result<Record6<String, Long, String, String, Integer, String>> _list = dslContext.select(
                                    BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.ID.as("id"),
                                    BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.STARTDATE.as("startDate"),
                                    BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.TRAVELTITLE.as("travelTitle"),
                                    BS_TRAVELLINE_PLATPRETRAVELLINE.IMAGES.as("images"),
                                    DSL.field("0", Integer.class).as("peopleNum"),
                                    BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.EXTINFOR.as("extInfor")
                            )
                            .from(
                                    DSL.select(
                                                    BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.ID.as("id"),
                                                    BS_TRAVELGROUP_BINDKEY.MODIFYTIME
                                            ).from(
                                                    BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD,
                                                    BS_TRAVELGROUP_BINDKEY
                                            )
                                            .where(
                                                    BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.TYPE.eq(Enum_TourTravelGroupType.Self.getCode())
                                            )
                                            .and(
                                                    BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.STATS.eq(Enum_MainTourTravelLineStats.Wait.getCode())
                                            )
                                            .and(
                                                    BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.EXPIREDATE.ge(System.currentTimeMillis())
                                            ).and(
                                                    BS_TRAVELGROUP_BINDKEY.STATS.eq(Enum_TravelGroupBindKeyStats.Top.getCode())
                                            ).and(
                                                    (model.getKeys() == null || model.getKeys().isEmpty()) ? DSL.noCondition() : BS_TRAVELGROUP_BINDKEY.KEYCODE.in(model.getKeys())
                                            ).and(
                                                    BS_TRAVELGROUP_BINDKEY.TRAVELGROUPID.eq(BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.ID)
                                            )
                                            .orderBy(
                                                    BS_TRAVELGROUP_BINDKEY.MODIFYTIME.asc()
                                            )
                                            .limit(model.getPagesize() * model.getCpage(), model.getPagesize())
                                            .asTable("t")
                            )
                            .leftJoin(BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD)
                            .on(BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.ID.eq(DSL.field("t.id", String.class)))
                            .leftJoin(BS_TRAVELLINE_PLATPRETRAVELLINE)
                            .on(BS_TRAVELLINE_PLATPRETRAVELLINE.ID.eq(BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.PRETRAVELLINEID))
                            .fetch();
                    Gson gson = new Gson();
                    _list.forEach(o -> {
                        ids.add(o.get("id", String.class));
                        java.util.List<String> images = new ArrayList<>();
                        try {
                            images = gson.fromJson(o.get("images", String.class), new TypeToken<List<String>>() {
                            }.getType());
                        } catch (Exception e) {
                            images = Arrays.asList(o.get("images", String.class).split(","));
                        }
                        rslist.add(new VPO_getHomePageTravelGroupListByKey(
                                o.get("id", String.class),
                                o.get("startDate", Long.class),
                                o.get("travelTitle", String.class),
                                images,
                                gson.fromJson(o.get("extInfor", String.class), java.util.Map.class),
                                o.get("peopleNum", Integer.class),
                                new ArrayList<>()
                        ));
                    });
                }
                CountDownLatch latch = new CountDownLatch(2);
                //统计报名人数
                java.util.Map<String, Integer> peopleNumMap = new HashMap<>();
                queryService.execute(() -> {
                    try {
                        java.util.List<_COUNT_getHomePageTravelGroupListByKey> ls = dslContext.select(
                                        BS_TRAVELGROUP_TOURORDERRECORD.TRAVELGROUPID,
                                        DSL.count(BS_TRAVELGROUP_TOURORDERRECORD.ID).as("n")
                                ).from(BS_TRAVELGROUP_TOURORDERRECORD)
                                .where(
                                        BS_TRAVELGROUP_TOURORDERRECORD.STATS.in(
                                                Enum_TravelGroupTourOrderStats.Waitpay.getCode(),
                                                Enum_TravelGroupTourOrderStats.Join.getCode(),
                                                Enum_TravelGroupTourOrderStats.Payed.getCode()
                                        )
                                )
                                .and(BS_TRAVELGROUP_TOURORDERRECORD.TRAVELGROUPID.in(ids))
                                .fetchInto(_COUNT_getHomePageTravelGroupListByKey.class);
                        if (!(ls == null || ls.isEmpty())) {
                            peopleNumMap.putAll(ls.stream().collect(Collectors.toMap(o -> o.getTravelGroupId(), o -> o.getN())));
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        latch.countDown();
                    }
                });
                //查询报名人头像
                java.util.Map<String, java.util.List<String>> userHeadCoverMap = new HashMap<>();
                queryService.execute(() -> {
                    try {

                        java.util.List<_HEADCOVER_getHomePageTravelGroupListByKey> ls = dslContext
                                .select(
                                        DSL.field("t.travelGroupId", String.class).as("travelGroupId"),
                                        DSL.field("BS_UserLayout_UserInfor.cover", String.class).as("headCover")
                                )
                                .from(
                                        DSL.select(
                                                        BS_TRAVELGROUP_TOURORDERRECORD.TRAVELGROUPID.as("travelGroupId"),
                                                        BS_TRAVELGROUP_TOURORDERRECORD.USERID.as("userId")
                                                ).from(BS_TRAVELGROUP_TOURORDERRECORD)
                                                .where(
                                                        BS_TRAVELGROUP_TOURORDERRECORD.STATS.in(
                                                                Enum_TravelGroupTourOrderStats.Waitpay.getCode(),
                                                                Enum_TravelGroupTourOrderStats.Join.getCode(),
                                                                Enum_TravelGroupTourOrderStats.Payed.getCode()
                                                        )
                                                )
                                                .and(BS_TRAVELGROUP_TOURORDERRECORD.TRAVELGROUPID.in(ids))
                                                .asTable("t")
                                )
                                .leftJoin("BS_UserLayout_UserInfor")
                                .on("BS_UserLayout_UserInfor.id=t.userId")
                                .fetchInto(_HEADCOVER_getHomePageTravelGroupListByKey.class);
                        ls.stream().forEach(o -> {
                            java.util.List<String> l = userHeadCoverMap.get(o.getTravelGroupId());
                            if (l == null) {
                                l = new ArrayList<>();
                                userHeadCoverMap.put(o.getTravelGroupId(), l);
                            }
                            l.add(o.getHeadCover());
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        latch.countDown();
                    }
                });

                try {
                    latch.await(30, TimeUnit.SECONDS);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                rslist.forEach(o -> {
                    //更新报名人数
                    Integer n = peopleNumMap.get(o.getId());
                    o.setPeopleNum(n == null ? 0 : n);
                    //更新头像
                    java.util.List<String> hl = userHeadCoverMap.get(o.getId());
                    o.setUserHeadCovers(hl == null ? new ArrayList<>() : hl);
                });
                dslContext.commit();
                return suc(rslist, count, "suc", "操作成功");
            });
        } catch (Exception e) {
            e.printStackTrace();
            return err("trans-err", e.getMessage());
        }
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class Model_getPreTravelLineById {
        private String id;
    }

    /**
     * 查询预设路线详情
     *
     * @param model
     * @return
     */
    @Deprecated
    public DataBean getPreTravelLineById(Model_getPreTravelLineById model) {
        try {
            return dslContext.transactionResult(ctx -> {
                //查询预设路线

                //查询关联景点

                //整合


                dslContext.commit();
                return suc(true, 1, "suc", "操作成功");
            });
        } catch (Exception e) {
            e.printStackTrace();
            return err("trans-err", e.getMessage());
        }
    }

    /**
     * 报名以及候补报名人数
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class _REPORT_MARK_PEOPLENUM_ {
        private Integer reportNum;// 报名人数
        private Integer markNum;//候补人数
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class Model_getTravelListGroupById {
        private String travelListGroupId;//大团ID
        private String defaultStartDate;//默认出发日期
    }

    /**
     * 上车点
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class _TourStartPoint_ {
        private String cityName;//城市
        private String address;//上车点
        private Integer num;//报名上车人数
    }


    /**
     * 查询大团详情
     *
     * @param model
     * @return
     */
    public DataBean getTravelListGroupById(
            Model_getTravelListGroupById model
    ) {
        try {
            return dslContext.transactionResult(ctx -> {
                //查询大团对象
                BsTravelGroupTraveListGroupDTO travelListGroupMoel = dslContext.selectFrom(
                                BS_TRAVELGROUP_TRAVELISTGROUP
                        ).where(
                                BS_TRAVELGROUP_TRAVELISTGROUP.ID.eq(model.getTravelListGroupId())
                        )
                        .limit(1).fetchOneInto(BsTravelGroupTraveListGroupDTO.class);
                if (travelListGroupMoel == null) {
                    return DataBean.errEmpty();
                }

                Future<BsTravelGroupMainTuorTravelLineRecordDTO> mainTuorTravelLineRecordDTOFuture = queryService.submit(new Callable<BsTravelGroupMainTuorTravelLineRecordDTO>() {
                    @Override
                    public BsTravelGroupMainTuorTravelLineRecordDTO call() throws Exception {

                        BsTravelGroupMainTuorTravelLineRecordDTO mainTuorTravelLineRecordDTO = dslContext.selectFrom(BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD)
                                .where(
                                        BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.ID.eq(
                                                DSL.select(
                                                                BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.MAINTOURTRAVELRECORDID
                                                        ).from(BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP)
                                                        .where(
                                                                BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.TRAVELLISTGROUPID.eq(model.getTravelListGroupId())
                                                        ).limit(0, 1)
                                        )
                                )
                                .limit(1).fetchOneInto(
                                        BsTravelGroupMainTuorTravelLineRecordDTO.class
                                );
                        return mainTuorTravelLineRecordDTO;
                    }
                });

                //查询预设路线
                Future<BsTravelLinePlatPreTravelLineDTO> preTravelLineIdFuture = queryService.submit(new Callable<BsTravelLinePlatPreTravelLineDTO>() {
                    @Override
                    public BsTravelLinePlatPreTravelLineDTO call() throws Exception {

                        BsTravelGroupMainTuorTravelLineRecordDTO mainTuorTravelLineRecordDTO = dslContext.selectFrom(BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD)
                                .where(
                                        BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.ID.eq(
                                                DSL.select(
                                                                BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.MAINTOURTRAVELRECORDID
                                                        ).from(BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP)
                                                        .where(
                                                                BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.TRAVELLISTGROUPID.eq(model.getTravelListGroupId())
                                                        ).limit(0, 1)
                                        )
                                )
                                .limit(1).fetchOneInto(
                                        BsTravelGroupMainTuorTravelLineRecordDTO.class
                                );
                        Gson gson = new Gson();
                        java.util.List<_TravelLine_DayScenic_> dayScenicList = gson.fromJson(mainTuorTravelLineRecordDTO.getTravelLineRemark(), new com.google.gson.reflect.TypeToken<java.util.List<_TravelLine_DayScenic_>>() {
                        }.getType());
                        java.util.List<String> sids = new ArrayList<>();
                        for (_TravelLine_DayScenic_ c : dayScenicList) {
                            sids.add(c.getScenicId());
                        }
//                        java.util.Map<Integer,java.util.List<_TravelLine_DayScenic_>> dayScenicMap = dayScenicList.stream().collect(Collectors.groupingBy(_TravelLine_DayScenic_::getDayNum));
                        //查询景点
                        java.util.List<BsScenicDTO> scenicList = dslContext.selectFrom(
                                BS_SCENIC
                        ).where(
                                BS_SCENIC.ID.in(
                                        sids.stream().distinct().toList()
                                )
                        ).fetchInto(BsScenicDTO.class);
                        java.util.Map<String, BsScenicDTO> scenicDTOMap = scenicList.stream().collect(Collectors.toMap(BsScenicDTO::getId, o -> o));
                        for (_TravelLine_DayScenic_ c : dayScenicList) {
                            c.setScenicTitle(scenicDTOMap.get(c.getScenicId()).getTitle());
                        }

                        BsTravelLinePlatPreTravelLineDTO preline = dslContext.selectFrom(BS_TRAVELLINE_PLATPRETRAVELLINE)
                                .where(BS_TRAVELLINE_PLATPRETRAVELLINE.ID.eq(
                                        mainTuorTravelLineRecordDTO.getPreTravelLineId()
                                ))
                                .limit(1).fetchOneInto(BsTravelLinePlatPreTravelLineDTO.class);


                        java.util.Map<String, Object> extInfor = gson.fromJson(
                                preline.getExtInfor(),
                                new com.google.gson.reflect.TypeToken<java.util.Map<String, Object>>() {
                                }.getType()
                        );
                        extInfor.put("lineList", gson.toJson(dayScenicList));
                        return preline;
                    }
                });
                //查询报名人数
                Future<TourTravelImpl._REPORT_MARK_PEOPLENUM_> peoplenumFuture = queryService.submit(new Callable<TourTravelImpl._REPORT_MARK_PEOPLENUM_>() {
                    @Override
                    public TourTravelImpl._REPORT_MARK_PEOPLENUM_ call() throws Exception {
                        try {
                            java.util.List<TourTravelImpl._ORDER_RECORD_SIMPLE> ls = dslContext.select(
                                    BS_TRAVELGROUP_TOURORDERRECORD.USERID.as("userId"),
                                    BS_TRAVELGROUP_TOURORDERRECORD.STATS.as("stats")
                            ).from(
                                    BS_TRAVELGROUP_TOURORDERRECORD
                            ).where(
                                    BS_TRAVELGROUP_TOURORDERRECORD.STATS.in(
                                            Enum_TravelGroupTourOrderStats.Waitpay.getCode(),
                                            Enum_TravelGroupTourOrderStats.Join.getCode(),
                                            Enum_TravelGroupTourOrderStats.Payed.getCode(),
                                            Enum_TravelGroupTourOrderStats.Mark.getCode()
                                    )
                            ).and(
                                    BS_TRAVELGROUP_TOURORDERRECORD.TRAVELGROUPID.eq(
                                            DSL.select(
                                                    BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.ID
                                            ).from(
                                                    BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD
                                            ).where(
                                                    BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.ID.in(
                                                            DSL.select(
                                                                    BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.MAINTOURTRAVELRECORDID
                                                            ).from(
                                                                    BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP
                                                            ).where(
                                                                    BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.TRAVELLISTGROUPID.eq(model.getTravelListGroupId())
                                                            )
                                                    )
                                            ).and(
                                                    BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.STARTDATE.eq(DateUtil.parse(model.getDefaultStartDate()).getTime())
                                            )
                                    )
                            ).fetchInto(TourTravelImpl._ORDER_RECORD_SIMPLE.class);
                            int marknum = 0;
                            int reportnum = 0;
                            for (TourTravelImpl._ORDER_RECORD_SIMPLE s : ls) {
                                if (s.getStats().equals(Enum_TravelGroupTourOrderStats.Mark.getCode())) {
                                    marknum++;
                                } else {
                                    reportnum++;
                                }
                            }
                            TourTravelImpl._REPORT_MARK_PEOPLENUM_ rs = new TourTravelImpl._REPORT_MARK_PEOPLENUM_(reportnum, marknum);
                            return rs;
                        } finally {
                        }
                    }
                });
                //查询上车点人数
                Future<java.util.List<_TourStartPoint_>> startPointFuture = queryService.submit(new Callable<List<_TourStartPoint_>>() {
                    @Override
                    public List<_TourStartPoint_> call() throws Exception {
                        try {
                            return dslContext.transactionResult(ctx -> {
                                java.util.List<String> startPointList = dslContext.select(
                                        BS_TRAVELGROUP_TOURORDERRECORD.STARTPOINT
                                ).from(
                                        BS_TRAVELGROUP_TOURORDERRECORD
                                ).where(
                                        BS_TRAVELGROUP_TOURORDERRECORD.STATS.in(
                                                Enum_TravelGroupTourOrderStats.Waitpay.getCode(),
                                                Enum_TravelGroupTourOrderStats.Join.getCode(),
                                                Enum_TravelGroupTourOrderStats.Payed.getCode()
                                        )
                                ).and(
                                        BS_TRAVELGROUP_TOURORDERRECORD.TRAVELGROUPID.eq(
                                                DSL.select(
                                                        BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.ID
                                                ).from(
                                                        BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD
                                                ).where(
                                                        BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.ID.in(
                                                                DSL.select(
                                                                        BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.MAINTOURTRAVELRECORDID
                                                                ).from(
                                                                        BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP
                                                                ).where(
                                                                        BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.TRAVELLISTGROUPID.eq(model.getTravelListGroupId())
                                                                )
                                                        )
                                                ).and(
                                                        BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.STARTDATE.eq(DateUtil.parse(model.getDefaultStartDate()).getTime())
                                                )
                                        )
                                ).fetchInto(String.class);
                                Gson gson = new Gson();
                                java.util.Map<String, _TourStartPoint_> tspMap = new HashMap<>();
                                for (String s : startPointList) {
                                    _TourStartPoint_ _p = gson.fromJson(s, _TourStartPoint_.class);
                                    String md5 = MD5.create().digestHex(_p.getCityName() + "," + _p.getAddress());
                                    _TourStartPoint_ p = tspMap.get(md5);
                                    if (p == null) {
                                        p = new _TourStartPoint_(_p.getCityName(), _p.getAddress(), 0);
                                    }
                                    p.setNum(p.getNum() + 1);
                                    tspMap.put(md5, p);
                                }
                                java.util.List<_TourStartPoint_> plist = new ArrayList<>();
                                tspMap.forEach((k, v) -> {
                                    plist.add(v);
                                });
                                return plist;
                            });
                        } catch (Exception e) {
                            e.printStackTrace();
                            return new ArrayList<>();
                        } finally {

                        }

                    }
                });

                //查询评论
                Future<java.util.List<TourTravelImpl.VPO_getMainTravelLineRecordById_Comment>> commentListFuture = queryService.submit(new Callable<List<TourTravelImpl.VPO_getMainTravelLineRecordById_Comment>>() {
                    @Override
                    public List<TourTravelImpl.VPO_getMainTravelLineRecordById_Comment> call() throws Exception {
                        try {
                            return dslContext.select(
                                            COUPLE_COMMENT.ID.as("id"),
                                            COUPLE_COMMENT.CREATE_TIME.as("createTime"),
                                            COUPLE_COMMENT.CONTENT.as("content"),
                                            COUPLE_COMMENT.ZAN_NUM.as("zan"),
                                            BS_USERLAYOUT_USERINFOR.ID.as("userId"),
                                            BS_USERLAYOUT_USERINFOR.NICKNAME.as("nickName"),
                                            BS_USERLAYOUT_USERINFOR.COVER.as("cover")
                                    ).from(
                                            DSL.select(
                                                            COUPLE_COMMENT.ID.as("id")
                                                    ).from(COUPLE_COMMENT)
                                                    .where(
                                                            COUPLE_COMMENT.STATS.eq(Enum_CommentStats.Apply.getCode())
                                                    ).and(
                                                            COUPLE_COMMENT.COMMENT_TYPE.eq(Enum_CommentType.TourMainTravel.getCode())
                                                    ).and(
                                                            COUPLE_COMMENT.MAIN_ID.eq(
                                                                    DSL.select(
                                                                            BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.ID
                                                                    ).from(
                                                                            BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD
                                                                    ).where(
                                                                            BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.ID.in(
                                                                                    DSL.select(
                                                                                            BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.MAINTOURTRAVELRECORDID
                                                                                    ).from(
                                                                                            BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP
                                                                                    ).where(
                                                                                            BS_TRAVELGROUP_MAINTOURTRAVELRECORDBINDTRAVELLISTGROUP.TRAVELLISTGROUPID.eq(model.getTravelListGroupId())
                                                                                    )
                                                                            )
                                                                    ).and(
                                                                            BS_TRAVELGROUP_MAINTUORTRAVELLINERECORD.STARTDATE.eq(DateUtil.parse(model.getDefaultStartDate()).getTime())
                                                                    )
                                                            )
                                                    ).orderBy(
                                                            COUPLE_COMMENT.IS_TOP.desc(), COUPLE_COMMENT.CREATE_TIME.desc()
                                                    ).limit(
                                                            0, 5
                                                    ).asTable("t")
                                    )
                                    .leftJoin(COUPLE_COMMENT)
                                    .on(COUPLE_COMMENT.ID.eq("t.id"))
                                    .leftJoin(BS_USERLAYOUT_USERINFOR)
                                    .on(BS_USERLAYOUT_USERINFOR.ID.eq(COUPLE_COMMENT.USER_ID))
                                    .fetchInto(TourTravelImpl.VPO_getMainTravelLineRecordById_Comment.class);
                        } finally {
                        }
                    }
                });

                dslContext.commit();
                TourTravelImpl._REPORT_MARK_PEOPLENUM_ pn = peoplenumFuture.get();
                //与小团详情保持一致
//                return suc(Map.of(
//                        "mainTravelGroup", mainTuorTravelLineRecordDTOFuture.get(),//主路线
//                        "preline", preTravelLineIdFuture.get(),//预设路线
//                        "startPoints", startPointFuture.get(),//上车点报名统计
//                        "travelListGroup", travelListGroupMoel,//大团详情对象
//                        "markNum", pn.getMarkNum(),//候补报名人数
//                        "reportNum", pn.getReportNum(),//已报名人数
//                        "comments", commentListFuture.get()//评论
//                ), 1, "suc", "操作成功");


                return suc(Map.of(
                        "mainTravelGroup", mainTuorTravelLineRecordDTOFuture.get(),//主路线
                        "preline", preTravelLineIdFuture.get(),//预设路线
                        "startPoints", startPointFuture.get(),//上车点报名统计
                        "travelListGroup", travelListGroupMoel,//大团详情对象
                        "markNum", pn.getMarkNum(),//候补报名人数
                        "reportNum", pn.getReportNum(),//已报名人数
                        "comments", commentListFuture.get()//评论
                ), 1, "suc", "操作成功");

            });
        } catch (Exception e) {
            e.printStackTrace();
            return err("trans-err", e.getMessage());
        }
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @EqualsAndHashCode
    public static class Model_updateTravelListGroup {

        private String travelListID;//大团ID

//        private java.util.List<String> startFromCityIds;//出发城市ID

        private String mainStartPrice;//大团发车起步价格
        //        private java.util.List<_StartPoint_> startPoint;
//        private String startPoint;
        private _TitleGroup_ titleGroup;//标题组
        private java.util.List<String> images;
        //        private java.util.List<_TravelCalendar_> travelCalendars;
        private java.util.Map<String, Object> content;//内容页
        private java.util.List<_StepPrice_> stepPrices;//阶梯价格
        private java.util.Map<String, Object> extInfor;//内容页
    }


    /**
     * 修改大团信息
     *
     * @param model
     * @return
     */
    public DataBean updateTravelListGroup(
            Model_updateTravelListGroup model
    ) {
        try {
            return dslContext.transactionResult(ctx -> {
                //todo
                Gson gson = new Gson();
                BsTravelgroupTravelistgroupRecord record = dslContext.selectFrom(
                                BS_TRAVELGROUP_TRAVELISTGROUP
                        ).where(BS_TRAVELGROUP_TRAVELISTGROUP.ID.eq(model.getTravelListID()))
                        .fetchOne();
                if (record == null)
                    return DataBean.errEmpty();
                record.setMainstartprice(new BigDecimal(model.getMainStartPrice()));
                record.setTitlegroup(gson.toJson(model.getTitleGroup()));
                record.setImages(gson.toJson(model.getImages()));
                record.setContent(gson.toJson(model.getContent()));
                record.setStepprice(gson.toJson(model.getStepPrices()));
                record.setExtinfor(gson.toJson(model.getExtInfor()));
                record.update();
                dslContext.commit();
                return suc(true, 1, "suc", "操作成功");
            });
        } catch (Exception e) {
            e.printStackTrace();
            return err("trans-err", e.getMessage());
        }
    }
}
